function t(t, a, e) {
    return a in t ? Object.defineProperty(t, a, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[a] = e, t;
}

var a;

Page({
    data: (a = {
        isEdit: false,
        kind:1,
        cat_list: [],
        cat_show_list: [],
        cat_select_index: [0, 0, 0],
        cat_select_id: {id: -1, name: '未选择'},
        mch_cat_list: [],
        mch_cat_show_list: [],
        mch_cat_select_index: [0, 0],
        mch_cat_select_id: {id: -1, name: '未选择'},
        mch_id: 0,
        id: 0,//商品id
        postageIndex: -1,
        height: 0,
        beSubmit: !1,
        form: {},
        forehead: -1,
        page_loading: !1,
        unit: "件",
        iphone_x: !1,
        modal: !1,
        error: !1,
        set_cat: !1,
        set_mch_cat: !1,
        set_postage: !1,
        set_service: !1,
        confine: !1,
        goods_card: [],
        img: [],
        cat: [],
        card: [],
        goods:[],
        is_detail:'',
        goods_detail: '',
        beMove: !1,
        service: [],
        postage: [],
        actions: [ {
            name: "我知道啦",
            color: "#446dfd"
        } ],
        action: [ {
            name: "取消",
            color: "#666666"
        }, {
            name: "确认",
            color: "#446dfd",
            loading: !1
        } ],
        beCat: [ {
            label: "未选择"
        } ],
        beMchCat: [{
            label: "未选择"
        }],
        beChooseCat:[{
            label: "未选择"
        }],
        isChooseCat: [ "未选择" ],
        p_id: 0,
        s_id: 0,
        choose_cat_name: '',
        choose_cat_arr:[],
        bePostage: "",
        beService: [],
        in_cat: "",
        newIndex: "0",
        index: "0",
        mch_cat: [],
        attr:[],
        attr_show: !0,
        attr_group_arr:[],
        attrgroupname: '',
        attrclassname: [],
        in_mch_cat: "",
    }, t(a, "form", {}), t(a, "attr", []), t(a, "have_children", !1), t(a, "disabled", !0), 
    t(a, "hidden", !0), t(a, "flag", !1), t(a, "x", 0), t(a, "y", 0), t(a, "elements", []), 
    t(a, "img_src", ""), a),
    _longtap: function(t) {
        var a = this;
        wx.createSelectorQuery().selectAll(".move-img").fields({
            dataset: !0,
            rect: !0
        }, function(t) {
            a.setData({
                elements: t
            });
        }).exec();
        t.detail;
        var e = t.currentTarget.dataset.src, i = t.currentTarget.dataset.index;
        this.data.img[i].pic_url = "", this.setData({
            x: t.currentTarget.offsetLeft,
            y: t.currentTarget.offsetTop
        }), this.setData({
            hidden: !1,
            flag: !0,
            beMove: !0,
            img_src: e,
            img: this.data.img,
            beginIndex: i
        });
    },
    bindMchCatConfirm: function (e) {
        var data = e.detail.value
        var mch_cat_show_list = this.data.mch_cat_show_list
        var mch_cat_select_id = {
            id: -1,
            name: '未选择'
        }
        if (mch_cat_show_list[1][data[1]].id == -1) {
            mch_cat_select_id = mch_cat_show_list[0][data[0]]
        } else {
            mch_cat_select_id = mch_cat_show_list[1][data[1]]
        }
        this.setData({
            mch_cat_select_id: mch_cat_select_id,
            mch_cat_select_index: e.detail.value
        })
    },
    bindMchCatChange: function (e) {
        var mch_cat_show_list = this.data.mch_cat_show_list
        var mch_cat_select_index = this.data.mch_cat_select_index
        var mch_cat_list = this.data.mch_cat_list
        var data = e.detail
        if (data.column == 0) {
            if (mch_cat_list[data.value].cat.length == 0 || mch_cat_list[data.value].cat[0].name != '未选择') {
                mch_cat_list[data.value].cat.unshift({
                    id: -1,
                    name: '未选择',
                    cat: []
                })
            }
            mch_cat_show_list[1] = mch_cat_list[data.value].cat
            mch_cat_select_index[0] = data.value
            mch_cat_select_index[1] = 0
            this.setData({
                mch_cat_show_list: mch_cat_show_list,
                mch_cat_select_index: mch_cat_select_index
            })
        }
    },
    bindCatConfirm: function (e) {
        var data = e.detail.value
        var cat_show_list = this.data.cat_show_list
        var cat_select_id = {
            id: -1,
            name: '未选择'
        }
        if (cat_show_list[1][data[1]].id == -1 && cat_show_list[2][data[2]].id == -1) {
            cat_select_id = cat_show_list[0][data[0]]
        } else if (cat_show_list[1][data[1]].id != -1 && cat_show_list[2][data[2]].id == -1) {
            cat_select_id = cat_show_list[1][data[1]]
        } else {
            cat_select_id = cat_show_list[2][data[2]]
        }
        this.setData({
            cat_select_id: cat_select_id,
            cat_select_index: e.detail.value
        })
    },
    bindCatChange: function (e) {
        var cat_show_list = this.data.cat_show_list
        var cat_select_index = this.data.cat_select_index
        var cat_list = this.data.cat_list
        var data = e.detail
        if (data.column == 0) {
            if (cat_list[data.value].cat.length == 0 || cat_list[data.value].cat[0].name != '未选择') {
                cat_list[data.value].cat.unshift({
                    id: -1,
                    name: '未选择',
                    cat: []
                })
            }
            cat_show_list[1] = cat_list[data.value].cat
            cat_show_list[2] = [{
                id: -1,
                name: '未选择',
                cat: []
            }]
            cat_select_index[0] = data.value
            cat_select_index[1] = 0
            this.setData({
                cat_show_list: cat_show_list,
                cat_select_index: cat_select_index
            })
        }
        if (data.column == 1) {
            if (cat_list[cat_select_index[0]].cat[data.value].cat.length == 0 || cat_list[cat_select_index[0]].cat[data.value].cat[0].name != '未选择') {
                cat_list[cat_select_index[0]].cat[data.value].cat.unshift({
                    id: -1,
                    name: '未选择',
                    cat: []
                })
            }
            cat_show_list[2] = cat_list[cat_select_index[0]].cat[data.value].cat
            cat_select_index[1] = data.value
            cat_select_index[2] = 0
            this.setData({
                cat_show_list: cat_show_list,
                cat_select_index: cat_select_index
            })
        }
    },
    touchend: function(t) {
        var a = this;
        if (this.data.flag) {
            for (var e = t.changedTouches[0].pageX, i = t.changedTouches[0].pageY, s = this.data.elements, r = this.data.img, o = this.data.beginIndex, n = 0; n < s.length; n++) {
                var d = s[n];
                if (e > d.left && e < d.right && i > d.top && i < d.bottom) {
                    var c = d.dataset.index;
                    if (o < c) {
                        for (var g = r[o], h = o; h < c; h++) r[h] = r[h + 1];
                        r[c] = g;
                    }
                    if (o > c) {
                        for (var u = r[o], p = o; p > c; p--) r[p] = r[p - 1];
                        r[c] = u;
                    }
                    r[c].pic_url = this.data.img_src, this.setData({
                        img: r
                    });
                }
            }
            a.data.img[o].pic_url || (a.data.img[o].pic_url = a.data.img_src, a.setData({
                img: a.data.img
            })), this.setData({
                hidden: !0,
                flag: !1,
                beMove: !1,
                beginIndex: null
            });
        }
    },
    touchm: function(t) {
        if (this.data.flag) {
            var a = t.touches[0].pageX, e = t.touches[0].pageY;
            this.setData({
                x: a - 60,
                y: e - 129
            });
        }
    },
    add_attr: function() {
        this.setData({
            attr_show: !1
            });
    },
    pop: function(t) {
        var a = t.currentTarget.dataset.index, e = this.data.attr;
        e.splice(a, 1), this.setData({
            attr: e
        });
    },
    pop_attr: function(t){
        var e = this.data.attr;
        if(e.length <= 0){
            this.setData({
                attr_show: !0
            })
        }
    },
    pop_attr_class:function(t) {
        var that = this;
        var a = t.currentTarget.dataset.index, e = that.data.attr_group_arr;
        e.splice(a, 1), this.setData({
            attr_group_arr: e
        });
    },
    pop_attr_value: function (t) {
        var that = this;
        var a = t.currentTarget.dataset.index,
        c = t.currentTarget.dataset.cindex,
        e = that.data.attr_group_arr[c].attr_list;
        e.splice(a, 1);
        var s = that.data.attr_group_arr;
        s[c].attr_list = e;
        this.setData({
            attr_group_arr: s
        });  
        // 组成规格值
        var data_attr_group_arr = that.data.attr_group_arr;
        var post_attr_group_arr = [];
        for(var attr_group_arr_key in data_attr_group_arr){
            post_attr_group_arr.push(data_attr_group_arr[attr_group_arr_key].attr_list);
        }
        getApp().request({
            url: getApp().api.admin.goods.attr_arr_list,
            data: {attr_group_arr: JSON.stringify(post_attr_group_arr)},
            method: "post",
            success: function (t) {
                if(t.code == 0){
                    var attr_arr_list_arr = [];
                    for(var data_group_arr_key in t.data.attr_group_arr_data){
                        var a = {
                            attr_list: [],
                            attr_list_value:"",
                            stock: "",
                            price: "",
                            no: "",
                            weight: "",
                            pic: "",
                            share_commission_first: 0,
                            share_commission_second: 0,
                            share_commission_third: 0,
                            member_price: {}
                        };
                        var attr_list_arra = [];
                        var attr_list_value_arr = [];
                        for(var agadk in t.data.attr_group_arr_data[data_group_arr_key]){
                            attr_list_arra.push(
                                {
                                    attr_group_id: 0,
                                    attr_group_name: t.data.attr_group_arr_data[data_group_arr_key][agadk] ? t.data.attr_group_arr_data[data_group_arr_key][agadk].attr_group_name : '',
                                    attr_id:t.data.attr_group_arr_data[data_group_arr_key][agadk] ? t.data.attr_group_arr_data[data_group_arr_key][agadk].attr_id : 0,
                                    attr_name:t.data.attr_group_arr_data[data_group_arr_key][agadk] ? t.data.attr_group_arr_data[data_group_arr_key][agadk].attr_name : ''
                                }
                            );
                            attr_list_value_arr.push(t.data.attr_group_arr_data[data_group_arr_key][agadk] ? t.data.attr_group_arr_data[data_group_arr_key][agadk].attr_name : '')
                        }
                        a.attr_list = attr_list_arra;
                        var agad =  attr_list_value_arr.join(',');
                        a.attr_list_value = agad;
                        attr_arr_list_arr.push(a)
                    }
                    that.setData({
                        attr: attr_arr_list_arr
                    });
                }
            }
        })
    },
    add_attr_class: function(e){
        var that = this;
        var t = that.data.attr_group_arr, a = {
            attr_group_id: t.length + 1,
            attr_group_name: that.data.attrgroupname,
            attr_list: []
        };
        t.push(a), that.setData({
            attr_group_arr: t,
            attrgroupname: ''
        });
    },
    add_attr_value: function (t) {
        var that = this;
        var i = t.currentTarget.dataset.index;
        var t = that.data.attr_group_arr[i].attr_list;
        a= {
            attr_id: 0,
            attr_name: that.data.attrclassname[i],
            attr_group_name: that.data.attr_group_arr[i].attr_group_name,
            attr_group_id: that.data.attr_group_arr[i].attr_group_id,
        };
        t.push(a);
        var s = that.data.attr_group_arr;
        s[i].attr_list = t;
        that.setData({
            attr_group_arr: s,
            attrclassname: []
        });

        // 组成规格值
        var data_attr_group_arr = that.data.attr_group_arr;
        var post_attr_group_arr = [];
        for(var attr_group_arr_key in data_attr_group_arr){
            post_attr_group_arr.push(data_attr_group_arr[attr_group_arr_key].attr_list);
        }
        getApp().request({
            url: getApp().api.admin.goods.attr_arr_list,
            data: {attr_group_arr: JSON.stringify(post_attr_group_arr)},
            method: "post",
            success: function (t) {
                if(t.code == 0){
                    var attr_arr_list_arr = [];
                    for(var data_group_arr_key in t.data.attr_group_arr_data){
                        var a = {
                            attr_list: [],
                            attr_list_value:"",
                            stock: "",
                            price: "",
                            no: "",
                            weight: "",
                            pic: "",
                            share_commission_first: 0,
                            share_commission_second: 0,
                            share_commission_third: 0,
                            member_price: {}
                        };
                        var attr_list_arra = [];
                        var attr_list_value_arr = [];
                        for(var agadk in t.data.attr_group_arr_data[data_group_arr_key]){
                            attr_list_arra.push(
                                {
                                    attr_group_id: 0,
                                    attr_group_name: t.data.attr_group_arr_data[data_group_arr_key][agadk] ? t.data.attr_group_arr_data[data_group_arr_key][agadk].attr_group_name : '',
                                    attr_id:t.data.attr_group_arr_data[data_group_arr_key][agadk] ? t.data.attr_group_arr_data[data_group_arr_key][agadk].attr_id : 0,
                                    attr_name:t.data.attr_group_arr_data[data_group_arr_key][agadk] ? t.data.attr_group_arr_data[data_group_arr_key][agadk].attr_name : ''
                                }
                            );
                            attr_list_value_arr.push(t.data.attr_group_arr_data[data_group_arr_key][agadk] ? t.data.attr_group_arr_data[data_group_arr_key][agadk].attr_name : '')
                        }
                        a.attr_list = attr_list_arra;
                        var agad =  attr_list_value_arr.join(',');
                        a.attr_list_value = agad;
                        attr_arr_list_arr.push(a)
                    }
                    that.setData({
                        attr: attr_arr_list_arr
                    });
                }
            }
        })
    },
    inputAttrGroup:function (t) {
        this.setData({
            attrgroupname: t.detail.value
        })
    },
    inputAttrClass:function (t) {
        var that = this;
        var a = t.currentTarget.dataset.index;

        var attrclassname_arr = that.data.attrclassname;
        attrclassname_arr[a] = t.detail.value;
        that.setData({
            attrclassname: attrclassname_arr
        })
    },
    inputAttr: function(t) {
        var a = t.currentTarget.dataset.index, e = this.data.attr;
        e[a].attr_list[0].attr_name = t.detail.value, e[a].attr_list[0].attr_id = (+a + 2).toString(), 
        console.log(e[a], a, e), this.setData({
            attr: e
        });
    },
    inputPrice: function(t) {
        var a = t.currentTarget.dataset.index, e = this.data.attr;
        e[a].price = t.detail.value, this.setData({
            attr: e
        });
    },
    inputNum: function(t) {
        var a = t.currentTarget.dataset.index, e = this.data.attr;
        e[a].num = t.detail.value, this.setData({
            attr: e
        });
    },
    inputNo: function(t) {
        var a = t.currentTarget.dataset.index, e = this.data.attr;
        e[a].no = t.detail.value, this.setData({
            attr: e
        });
    },
    inputWeight: function(t) {
        var a = t.currentTarget.dataset.index, e = this.data.attr;
        e[a].weight = t.detail.value, this.setData({
            attr: e
        });
    },
    name: function(t) {
        var a = this.data.form;
        a.name = t.detail.value, this.setData({
            form: a
        });
    },
    unit: function(t) {
        var a = this.data.form;
        a.unit = t.detail.value, this.setData({
            form: a,
            unit: t.detail.value
        });
    },
    cost_price: function(t) {
        var a = this.data.form;
        a.cost_price = t.detail.value, this.setData({
            form: a
        });
    },
    original_price: function(t) {
        var a = this.data.form;
        a.original_price = t.detail.value, this.setData({
            form: a
        });
    },
    service_content: function (t) {
      var a = this.data.form;
      a.service = t.detail.value, this.setData({
        form: a
      });
    },
    price: function(t) {
        var a = this.data.form;
        a.price = t.detail.value, this.setData({
            form: a
        });
    },
    pieces: function(t) {
        var a = this.data.form;
        a.pieces = t.detail.value, this.setData({
            form: a
        });
    },
    forehead: function(t) {
        var a = this.data.form;
        a.forehead = t.detail.value, this.setData({
            form: a
        });
    },
    confineSwitch: function() {
        this.setData({
            confine: !this.data.confine
        });
    },
    confine_count: function(t) {
        var a = this.data.form;
        a.confine_count = t.detail.value, this.setData({
            form: a
        });
    },
    forehead_integral: function(t) {
        var a = this.data.form;
        a.forehead_integral = t.detail.value, this.setData({
            form: a
        });
    },
    give_integral: function(t) {
        var a = this.data.form;
        a.give_integral = t.detail.value, this.setData({
            form: a
        });
    },
    goods_num: function(t) {
        var a = this.data.form;
        a.goods_num = t.detail.value, this.setData({
            form: a
        });
    },
    onLoad: function(t) {
        var a = this;

      getApp().page.onLoad(this, t);
      this.setData({
        kind: t.kind
      });
      var title = t.kind==1?'课程':'商品';
      if (t.mch_id) {
          this.setData({
              mch_id: t.mch_id
          });
          wx.setNavigationBarTitle({
            title: '添加'+title,
          })
      }
      
      //商品id
      if (t.id) {
        this.setData({
            id: t.id
        });
        wx.setNavigationBarTitle({
          title: '编辑'+title,
        })
      }
        getApp().core.getSystemInfo({
            success: function(t) {
                var e = t.windowHeight * (750 / t.windowWidth);
                a.setData({
                    height: e
                });
            }
        }), getApp().device().indexOf("iphone_x") > -1 && this.setData({
            iphone_x: !0
        }), this.getCat(), this.data.mch_id > 0 && this.getMchCat(),this.getService(), this.getPostage(), this.getCard(), getApp().core.removeStorage({
            key: "goods_card",
            success: function(t) {
                a.setData({
                    goods_card: []
                });
            }
        }), getApp().core.removeStorage({
            key: "goods_detail",
            success: function(t) {
                // a.setData({
                //     goods_detail: ''
                // });
            }
        }),getApp().request({
            url: getApp().api.admin.goods.edit,
            data: {id: a.data.id},
            method: "get",
            success: function (t) {
                if (0 == t.code) {
                    var e = t.data;
                    //商品图片
                    var goods_imgs = [];
                    for (var key in e.goods_pic_list) {
                        var o = {
                            pic_url: e.goods_pic_list[key].pic_url, 
                        };
                        goods_imgs.push(o);
                    }
                    //商品规格
                    //限购
                    if(e.goods.confine_count > 0){
                        a.setData({
                            confine: !0
                        })
                    }
                    //运费设置
                    if(e.goods.freight != 0){
                        getApp().request({
                            url: getApp().api.admin.goods.postage,
                            data: {
                            mch_id: t.data.mch_id
                            },
                            method: "get",
                            success: function(res) {
                            if (0 == res.code) {
                                var s = res.data.list;
                                for(var k in s){
                                    if(s[k].id = e.goods.freight){
                                        a.setData({
                                            bePostage: s[k]
                                        })
                                    }
                                }
                            }
                            }
                        });
                    }
                    // form表单默认值
                    var evl = a.data.form;
                    evl.name = e.goods.name;
                    // evl.cats = e.cat_info.cat_id;
                    evl.cost_price = e.goods.cost_price;
                    evl.original_price = e.goods.original_price;
                    evl.price = e.goods.price;
                    evl.goods_num = e.goods.goods_num;
                    evl.service = e.goods.service;
                    if (e.goods.full_cut != 'null') {
                        evl.pieces = JSON.parse(e.goods.full_cut).pieces;
                        evl.forehead = JSON.parse(e.goods.full_cut).forehead;
                    } else {
                        evl.pieces = '';
                        evl.forehead = '';
                    }
                    if (e.goods.integral) {
                        evl.integral = JSON.parse(e.goods.integral).confine_count;
                    } else {
                        evl.integral = '';
                    }
                    evl.detail = e.goods.detail;
                    evl.attr = e.goods.attr;
                    // 规格
                    if(e.goods.attr != null && e.goods.attr.length > 1){
                        a.setData({
                            attr_show: !1,
                        })
                    }
                    var attr_list_value = '';
                    for (var attr_k in e.goods.attr){
                        for(var attr_list_k in e.goods.attr[attr_k].attr_list){
                            attr_list_value = attr_list_value  + e.goods.attr[attr_k].attr_list[attr_list_k].attr_name + ',';
                        }
                        attr_list_value=attr_list_value.slice(0, -1);
                        e.goods.attr[attr_k].attr_list_value = attr_list_value;
                        attr_list_value = '';
                    }
                    var attr_group_list = JSON.parse(e.attr_group_list);
                    var attr_list_arr = [];
                    for(var attr_group_key in attr_group_list){
                        for(var attr_list_key  in attr_group_list[attr_group_key].attr_list){
                            var attr_list_value_arr = {
                                attr_id: attr_group_list[attr_group_key].attr_list[attr_list_key].attr_id,
                                attr_name: attr_group_list[attr_group_key].attr_list[attr_list_key].attr_name,
                                attr_group_name: attr_group_list[attr_group_key].attr_group_name,
                            };
                            attr_list_arr.push(attr_list_value_arr);
                        }
                        attr_group_list[attr_group_key].attr_list = attr_list_arr;
                        attr_list_arr = [];
                    }
                    var goods_detail = e.goods.detail;
                    getApp().core.setStorage({
                        key: "goods_detail",
                        data: e.goods.detail
                    })

                    a.setData({
                        form: evl,
                        img: goods_imgs,
                        goods: e.goods,
                        attr: e.goods.attr,
                        attr_group_arr:attr_group_list,
                        cat_select_id: {
                            id: e.cat_info.cat_id,
                            name: e.cat_info.cat_name
                        },
                        unit: e.goods.unit ? e.goods.unit : '件',
                        is_detail: e.goods.detail,// 已有商品详情
                        goods_detail: e.goods.detail,
                        full_cut: JSON.parse(e.goods.full_cut),
                        integral:JSON.parse(e.goods.integral),
                        getCheckedAttrData: e.getCheckedAttrData
                    });
                    // if (a.data.mch_id > 0 && a.data.id > 0) {
                        a.setData({
                            mch_cat_select_id: {
                                id: e.mch_cat_info.cat_id,
                                name: e.mch_cat_info.cat_name
                            }
                        })
                    // }
                }
            }
        });
    },
    bindChange: function(t) {
        var that = this;
        var a = t.detail.value;
        var choose_cat_name = '';
        var choose_cat_array = [];
        var cat_arr = that.data.cat;
        if(cat_arr[a[0]]['cat'][a[1]]['cat'].length > 0){
            choose_cat_name = cat_arr[a[0]]['cat'][a[1]]['cat'][a[2]]['name'];
            choose_cat_array = cat_arr[a[0]]['cat'][a[1]]['cat'][a[2]];
        }else if(cat_arr[a[0]]['cat'].length > 0){
            choose_cat_name = cat_arr[a[0]]['cat'][a[1]]['name'];
            choose_cat_array = cat_arr[a[0]]['cat'][a[1]];
        }else{
            choose_cat_name = cat_arr[a[0]]['name'];
            choose_cat_array = cat_arr[a[0]];
        }
        that.setData({
            newIndex: a[0],
            p_id: a[0],
            s_id: a[1],
            choose_cat_name: choose_cat_name,
            choose_cat_arr: choose_cat_array
        });
    },
    close: function() {
        this.setData({
            modal: !this.data.modal,
            set_card: !1,
            set_cat: !1,
            set_mch_cat: !1,
            set_service: !1,
            set_postage: !1
        });
    },
    add_img: function() {
        var t = this, a = 9 - t.data.img.length;
        getApp().core.chooseImage({
            count: a,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var e = a.tempFilePaths, i = t.data.img;
                e.forEach(function(a, s) {
                    getApp().core.showLoading({
                        type: "loading"
                    }), getApp().core.uploadFile({
                        url: getApp().api.default.upload_image,
                        filePath: a,
                        name: "image",
                        // formData: {
                        //     user: "test"
                        // },
                        success: function(a) {
                          getApp().core.hideLoading()
                            var r = JSON.parse(a.data), o = {
                                pic_url: r.data.url,
                                id: r.data.id
                            };
                            0 == r.code && i.push(o), t.setData({
                                img: i
                            }), s == e.length - 1;
                        }
                    });
                });
            }
        });
    },
    del_img: function(t) {
        var a = t.currentTarget.dataset.index, e = this.data.img;
        e.splice(a, 1), this.setData({
            img: e
        });
    },
    chooseCat: function(t) {
        0 == this.data.cat.length ? this.setData({
            modal: !0,
            set_cat: !0
        }) : this.setData({
            choose_list: this.data.cat,
            choose_cat: !0,
            dialog: !0,
            set_cat: !0,
            in_cat: null,
            index: 0,
            have_children: !1,
            beCat: [ {
                label: "未选择"
            } ],
            isChooseCat: [ "未选择" ]
        });
    },
    chooseMchCat: function () {
        0 == this.data.mch_cat.length ? this.setData({
            modal: !0,
            set_mch_cat: !0
        }) : this.setData({
            choose_list: this.data.mch_cat,
            dialog: !0,
            set_mch_cat: !0,
            in_mch_cat: null,
            index: 0,
            have_children: !1,
            beMchCat: [{
                label: "未选择"
            }],
            isChooseCat: ["未选择"]
        });
    },
    choose_cat: function() {
        var that = this;
        var choose_cat_arr_array = [that.data.choose_cat_arr];
        that.setData({
            beChooseCat: choose_cat_arr_array
        });
        var chs = this.data.beChooseCat;

        var t = this.data.beCat, a = !1, e = this.data.cat[this.data.newIndex], i = this.data.index;
        if (this.data.have_children && (e = t[i - 1].children[this.data.newIndex - 1]), 
        t[i] = e, this.setData({
            choose_list: []
        }), i++, e) {
            // 商品分类选择 begin 
            if(that.data.choose_cat){
                t = chs;
                that.setData({
                    in_cat: that.data.choose_cat_name,
                    dialog: !1,
                    set_cat: !1
                });
            }else{
                var s = [];
                if (t.forEach(function(t, a) {
                s.push(t.name);
                }), s.push("未选择"), this.setData({
                    isChooseCat: s
                }), e.children) {
                    var r = [];
                    r[0] = {
                    name: "不选择"
                    }, e.children.forEach(function(t) {
                        r.push(t);
                    }), a = !0, this.setData({
                        choose_list: r
                    });
                } else {
                    var o = void 0;
                    t.forEach(function(t, a) {
                    t.name.length > 5 && (t.name = t.label.slice(0, 4) + "..."), 0 == a ? o = t.name : o += "/" + t.name;
                    }), this.setData({
                        in_cat: o,
                        dialog: !1,
                        set_cat: !1
                    });
                }
            }
        } else {
            t.pop();
            var n = void 0;
            t.forEach(function(t, a) {
                0 == a ? n = t.label : n += "/" + t.label;
            }), this.setData({
                in_cat: n,
                dialog: !1,
                set_cat: !1
            });
        }
        this.setData({
            newIndex: "0",
            beCat: t,
            index: i,
            have_children: a
        });
    },
    choose_mch_cat: function () {
        var that = this;
        var choose_cat_arr_array = [that.data.choose_cat_arr];
        that.setData({
            beChooseCat: choose_cat_arr_array
        });
        var chs = this.data.beChooseCat;

        var t = this.data.beMchCat, a = !1, e = this.data.mch_cat[this.data.newIndex], i = this.data.index;
        if (this.data.have_children && (e = t[i - 1].children[this.data.newIndex - 1]),
            t[i] = e, this.setData({
                choose_list: []
            }), i++ , e) {
            // 商品分类选择 begin 
            // if(that.data.choose_cat){
            //     t = chs;
            //     that.setData({
            //         in_cat: that.data.choose_cat_name,
            //         dialog: !1,
            //         set_cat: !1
            //     });
            //     console.log(123456)
            // }else{
                var s = [];
                if (t.forEach(function (t, a) {
                    s.push(t.name);
                }), s.push("未选择"), this.setData({
                    isChooseCat: s
                }), e.children) {
                    var r = [];
                    r[0] = {
                        label: "不选择"
                    }, e.children.forEach(function (t) {
                        r.push(t);
                    }), a = !0, this.setData({
                        choose_list: r
                    });
                } else {
                    var o = void 0;
                    t.forEach(function (t, a) {
                        t.name.length > 5 && (t.name = t.name.slice(0, 4) + "..."), 0 == a ? o = t.name : o += "/" + t.name;
                    }), this.setData({
                        in_mch_cat: o,
                        dialog: !1,
                        set_mch_cat: !1
                    });
                }
            // }
        } else {
            t.pop();
            var n = void 0;
            t.forEach(function (t, a) {
                0 == a ? n = t.label : n += "/" + t.label;
            }), this.setData({
                in_mch_cat: n,
                dialog: !1,
                set_mch_cat: !1
            });
        }
        this.setData({
            newIndex: "0",
            beMchCat: t,
            index: i,
            have_children: a
        });
    },
    toggle: function(t) {
        var a = t.currentTarget.dataset.status;
        if (2 == a) this.setData({
            choose_list: [],
            dialog: !1,
            set_cat: !1,
            set_mch_cat: !1,
            set_postage: !1
        }); else if (1 == a && this.data.set_postage) {
            var e = this.data.postage[this.data.newIndex];
            this.setData({
                bePostage: e,
                choose_list: [],
                dialog: !1,
                set_mch_cat: !1,
                set_cat: !1,
                set_postage: !1
            });
        }
    },
    getCat: function() {
        var t = this;
        getApp().core.showLoading()
        getApp().request({
            url: getApp().api.admin.goods.get_cat,
            data: {
              mch_id: t.data.mch_id
            },
            method: "get",
            success:function (a) {
              getApp().core.hideLoading()
              if ( 0 == a.code) {
                // var e = a.data.list;
                var e = [a.data.mch];
                e[0].cat=[];
                if (!e[0]) {
                    return;
                }
                var alist = e;
                var cat_show_list = [];
                cat_show_list[0] = e;
                e[0].cat.unshift({
                    id: -1,
                    name: '未选择',
                    cat: []
                })
                cat_show_list[1] = e[0].cat
                cat_show_list[2] = [{
                    id: -1,
                    name: '未选择',
                    cat: []
                }]
                console.log(cat_show_list)
                t.setData({
                    cat_show_list: cat_show_list,
                    // cat_list: a.data.list
                    cat_list: alist
                })
                var e = a.data.list;
                    for(var i=0; i < e.length; i++){
                        e[i].cat = [];
                    }
                    var alist = e;
                    var mch_cat_show_list = [];
                    mch_cat_show_list[0] = e;
                    e[0].cat.unshift({
                        id: -1,
                        name: '未选择',
                        cat: []
                    })
                    mch_cat_show_list[1] = e[0].cat
                    t.setData({
                        mch_cat_show_list: mch_cat_show_list,
                        mch_cat_list: alist
                    })
              } else getApp().core.showToast({
                title: a.msg,
                icon: 'none'
              });
            },
            fale: function (t) {
              getApp().core.hideLoading()
              getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              })
            }
        });
    },
    getMchCat: function () {
        var t = this;
        getApp().core.showLoading()
        getApp().request({
            url: getApp().api.admin.goods.get_mch_cat,
            data: {mch_id: t.data.mch_id},
            method: "get",
            success: function (a) {
                getApp().core.hideLoading()
                if (0 == a.code) {
                    // var e = a.data.list;
                    // var mch_cat_show_list = [];
                    // mch_cat_show_list[0] = e;
                    // e[0].cat.unshift({
                    //     id: -1,
                    //     name: '未选择',
                    //     cat: []
                    // })
                    // mch_cat_show_list[1] = e[0].cat
                    // t.setData({
                    //     mch_cat_show_list: mch_cat_show_list,
                    //     mch_cat_list: a.data.list
                    // })
                } else getApp().core.showToast({
                    title: a.msg,
                    icon: 'none'
                });
            },
            fale: function (t) {
                getApp().core.hideLoading()
                getApp().core.showToast({
                    title: t.msg,
                    icon: 'none'
                })
            }
        });
    },
    chooseExpress: function() {
        var t = this;
        getApp().core.showLoading()
        getApp().request({
            url: getApp().api.admin.goods.postage,
            data: {
              mch_id: t.data.mch_id
            },
            method: "get",
            success: function(a) {
              getApp().core.hideLoading()
              if (0 == a.code) {
                var e = a.data.list;
                if (0 == e.length) t.setData({
                  set_postage: !0,
                  modal: !0,
                  postage: e
                }); else {
                  var i = [];
                  e.forEach(function (t, a) {
                    i.push(e[a].id);
                  });
                  var s = i.indexOf(t.data.bePostage.id);
                  s > -1 ? t.setData({
                    postageIndex: s,
                    newIndex: s
                  }) : t.setData({
                    bePostage: ""
                  }), t.setData({
                    set_postage: !0,
                    dialog: !0,
                    postage: e
                  });
                }
              }
            }
        });
    },
    chooseService: function() {
      return [];
        var t = this;
        getApp().request({
            url: getApp().apiUrl.app_admin.service,
            data: {
              mch_id: t.data.mch_id
            },
            method: "get"
        }).then(function(a) {
            if (getApp().iView.$Toast.hide(), 0 == a.data.code) {
                var e = a.data.data.list, i = [];
                e.forEach(function(t) {
                    t.isChoose = !1, 1 == t.is_default && (i.push(t), t.isChoose = !0);
                }), t.setData({
                    service: e,
                    beService: i
                }), 0 == e.length ? t.setData({
                    set_service: !0,
                    modal: !0
                }) : t.setData({
                    set_service: !0,
                    is_service: !0
                });
            } else getApp().iView.$Toast({
                content: a.data.msg,
                duration: 2,
                type: "warning"
            });
        });
    },
    chooseCard: function() {
        var t = this;
        getApp().core.showLoading();
        getApp().request({
            url: getApp().api.admin.goods.card,
            data: {
              mch_id: t.data.mch_id
            },
            method: "get",
            success: function(a) {
              getApp().core.hideLoading()
              if (0 == a.code) {
                var e = a.data.list;
                t.setData({
                  card: e
                }), 0 == e.length ? t.setData({
                  set_card: !0,
                  modal: !0
                }) : [];
              } else getApp().core.showToast({
                title: a.msg,
                icon: 'none'
              });
            }
        });
    },
    choose: function(t) {
        var a = this.data.beService, e = t.currentTarget.dataset.detail;
        this.data.service.forEach(function(t) {
            t.id == e.id && (t.isChoose = !t.isChoose);
        }), this.setData({
            beService: a,
            service: this.data.service
        });
    },
    submitService: function(t) {
        var a = t.detail.index;
        if (0 === a) {
            var e = this.data.beService, i = this.data.service;
            e.length > 0 ? i.forEach(function(t, a) {
                t.isChoose = !1, e.forEach(function(a) {
                    a.id == t.id && (t.isChoose = !0);
                });
            }) : i.forEach(function(t, a) {
                t.isChoose = !1;
            }), this.setData({
                beService: e,
                service: i,
                set_service: !1,
                is_service: !1
            });
        } else if (1 === a) {
            var s = [];
            this.data.service.forEach(function(t) {
                t.isChoose && s.push(t);
            }), this.setData({
                beService: s,
                set_service: !1,
                is_service: !1
            });
        }
    },
    getService: function() {
        var t = this;
        return [];
        getApp().request({
            url: getApp().apiUrl.app_admin.service,
            data: {
              mch_id: t.data.mch_id
            },
            method: "get"
        }).then(function(a) {
            if (getApp().iView.$Toast.hide(), 0 == a.data.code) {
                var e = a.data.data.list, i = [];
                e.forEach(function(t) {
                    t.isChoose = !1, 1 == t.is_default && (i.push(t), t.isChoose = !0);
                }), t.setData({
                    service: e,
                    beService: i
                });
            } else getApp().iView.$Toast({
                content: a.data.msg,
                duration: 2,
                type: "warning"
            });
        }).catch(function(t) {
            getApp().iView.$Toast({
                content: t.data.msg,
                duration: 2,
                type: "error"
            });
        });
    },
    getCard: function() {
        var t = this;
        getApp().request({
            url: getApp().api.admin.goods.card,
            data: {
              mch_id: t.data.mch_id
            },
            method: "get",
            success: function (a) {
              if ( 0 == a.code) {
                var e = a.data.list;
                t.setData({
                  card: e
                });
                console.log(e)
              } else getApp().core.showToast({
                title: a.msg,
                icon: 'none'
              });
            },
            fale: function() {
              getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              });
            }
        });
    },
    getPostage: function() {
        var t = this;
        getApp().request({
            url: getApp().api.admin.goods.postage,
            data: {
              mch_id: t.data.mch_id
            },
            method: "get",
            success:function (a) {
              getApp().core.hideLoading()
              if ( 0 == a.code) {
                var e = a.data.list, i = "";
                e.forEach(function (t) {
                  1 == t.status && (i = t);
                }), t.setData({
                  postage: e,
                  bePostage: i
                });
              } else getApp().core.showToast({
                title: a.msg,
                icon: 'none'
              });
            },
            fale: function(t) {
              getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              });
            }
        });
    },
    submit: function() {
        var t = !1, a = this, e = a.data.form;
        if (!(a.data.img.length > 0)) return a.setData({
            error: "请上传商品图片"
        }), !1;
        if (e.pic_url = a.data.img, !e.name) return a.setData({
            error: "请设置商品名称"
        }), !1;
        if (e.cats = [], -1 == a.data.cat_select_id.id) return a.setData({
            error: "请设置商品分类"
        }), !1;
        if (e.cats.push(a.data.cat_select_id.id), e.mchCats = [], -1 == a.data.mch_cat_select_id.id && a.data.mch_id > 0) return a.setData({
            error: "请设置多商户商品分类"
        }), !1;
        if (e.mchCats.push(a.data.mch_cat_select_id.id),!a.data.unit) return a.setData({
            error: "请设置商品单位"
        }), !1;
        if (e.unit || (e.unit = a.data.unit), !e.cost_price) return a.setData({
            error: "请设置商品成本价"
        }), !1;
        if (e.cost_price < 0) return a.setData({
            error: "成本价不得小于零"
        }), !1;
        if (!e.original_price) return a.setData({
            error: "请设置商品原价"
        }), !1;
        if (e.original_price < 0) return a.setData({
            error: "商品原价不得小于零"
        }), !1;
        var is_error = false;
        if (a.data.attr.length > 0 && a.data.attr[0].attr_list[0].attr_name != '默认') {e.use_attr = 1, e.goods_num = 0, a.data.attr.forEach(function(e, i) {
            return a.data.attr[i].attr_list[0].attr_name ? a.data.attr[i].price ? a.data.attr[i].num !== '' ? void (i == a.data.attr.length - 1 && (t = !0)) : (a.setData({
                error: "请输入规格库存"
            }), !1, is_error = true) : (a.setData({
                error: "请输入规格售价"
            }), !1, is_error = true) : (a.setData({
                error: "请输入规格名"
            }), !1, is_error = true);
            // return a.data.attr[i].attr_list[0].attr_name ? a.data.attr[i].price ? !1 : (a.setData({
            //     error: "请输入规格售价"
            // }), !1) : (a.setData({
            //     error: "请输入规格名"
            // }), !1);
        }), e.attr = a.data.attr;
        if (is_error) {
            return 0;
        }
    } else {
            if (e.use_attr = 0, e.attr = [], !e.price) return a.setData({
                error: "请设置商品售价"
            }), !1;
            // console.log('商品库存', e.goods_num);
            // if (!e.goods_num) return a.setData({
            //     error: "商品库存不得为空"
            // }), !1;
            if (e.price < .01) return a.setData({
                error: "商品售价不得小于零"
            }), !1;
            t = !0;
        }
        if ((e.cards = a.data.goods_card, e.services = [], a.data.beService.length > 0 && (e.services = a.data.beService), 
        e.status = a.data.mch_id > 0 ? 0 : 1, e.virtual_sales = 0, e.cover_pic = "", e.sort = 100, e.accumulative = 1, 
        e.member_price = {},!(a.data.goods_detail)) && a.data.is_detail == '') return a.setData({
            error: "请设置图文描述"
        }), !1;
        e.detail = a.data.goods_detail,
        e.forehead_integral && (e.forehead_integral > 0 ? e.forehead_integral_type : (e.forehead_integral_type, 
        e.forehead_integral = e.forehead_integral.replace("%", ""))), e.give_integral && (e.give_integral > 0 ? e.give_integral_type : (e.give_integral_type, 
        e.give_integral = e.give_integral.replace("%", ""))), e.freight_id = a.data.bePostage.id, 
        e.freight = a.data.bePostage, e.individual_share = 0, e.is_level = 0, e.individual_share = 0, 
        e.video_url = "", e.mch_id = a.data.mch_id,t && a.setData({
            form: e,
            beSubmit: !0
        });
    },
    toSubmit: function() {
        var self = this;
        getApp().core.showLoading();
        getApp().request({
            url: getApp().api.admin.goods.edit + '&mch_id=' + self.data.mch_id,
            data: {
                form: JSON.stringify(this.data.form),
                id:self.data.id > 0 ? self.data.id : '',
                kind:self.data.kind
            },
            method: "post",
            success: function (t) {
              getApp().core.hideLoading(), 0 == t.code ? (getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              }),self.cancel(), getApp().core.setStorage({
                key: "goods_status",
                data: "保存成功"
              })
              , setTimeout(function () {
                if (self.data.mch_id > 0) {
                    getApp().core.navigateTo({
                        url: "/mch/m/goods/goods?status=3&kind="+self.data.kind
                    });
                } else {
                    getApp().core.navigateBack();
                }
              }, 500)
              )
               : getApp().core.showToast({
                title: t.msg,
                icon:'none'
              });
            },
            fale: function(t) {
              getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              })
            }
        });
    },
    cancel: function() {
        this.setData({
            beSubmit: !1
        });
    },
    getError: function() {
        this.setData({
            error: !1
        });
    },
    onReady: function(t) {
        this.setData({
            page_loading: !1
        });
    },
    onShow: function() {
        var t = this;
        getApp().core.getStorage({
            key: "goods_card",
            success: function(a) {
                t.setData({
                    goods_card: a.data
                });
            }
        }), getApp().core.getStorage({
            key: "goods_detail",
            success: function(a) {
                t.setData({
                    goods_detail: a.data
                });
            }
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});